import os
os.chdir('..')
import numpy as np
from DatasetInteraction import DatasetInteraction
from DatabaseInteraction import DatabaseInteraction

# 得到数据，返回数据的帧数
def getFrameSize(data):
    shape = data.shape
    return shape[2]

datasetInteraction = DatasetInteraction()
data, annotation = datasetInteraction.getDataset()

ClassIDToFramesSize = {}
for i in range(len(annotation)):
    classID = i % 60
    frameSize = getFrameSize(data[i])
    if classID not in ClassIDToFramesSize:
        ClassIDToFramesSize[classID] = []
    ClassIDToFramesSize[classID].append(frameSize)

for i in ClassIDToFramesSize.keys():
    ClassIDToFramesSize[i] = int(np.mean(ClassIDToFramesSize[i]))

np.save('Data/classIDToFramesSize.npy', ClassIDToFramesSize)

databaseInteraction = DatabaseInteraction()
idToClass = databaseInteraction.getIdToClassDict()

d = {}
for i in ClassIDToFramesSize.keys():
    name = idToClass[str(i)]
    d[name] = int(ClassIDToFramesSize[i])

np.save('Data/classToFramesSize.npy', d)